{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "5db1a772",
   "metadata": {},
   "source": [
    "# 第九周\n",
    ">1.while循环\n",
    "\n",
    "  2.购物车练习\n",
    "\n",
    "  3.元组_集合"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "41c3c1b1",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "456773cd",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "hide_card66\n"
     ]
    }
   ],
   "source": [
    "import getpass\n",
    "hide_card = int(input(\"hide_card\"))\n",
    "count = 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "3c778181",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "hide_card66\n"
     ]
    }
   ],
   "source": [
    "# 猜数字小游戏： 0<n<100,5次机会猜数字，每次猜完出题人提示你猜的有点大/有点小\n",
    "\n",
    "hide_card = int(input(\"hide_card\"))# 出题人\n",
    "count = 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ff51339f",
   "metadata": {},
   "outputs": [],
   "source": [
    "import getpass\n",
    "hide_card = int(input(\"hide_card\"))\n",
    "count = 0\n",
    "\n",
    "if hide_card < 100 and hide_card>0:\n",
    "  # print(\"游戏开始了\")\n",
    "    while True:\n",
    "        if count < 5:\n",
    "            guess_digit = int(input(\"guess_digit:\")) # 玩游戏的人\n",
    "            if guess_digit == hide_card:\n",
    "                print(\"yes,you got it.\")\n",
    "            elif guess_digit > hide_card:\n",
    "                print(\"往小了想想..\")\n",
    "            else:\n",
    "                 print(\"往大了猜\")\n",
    "            count = count+1\n",
    "        else:\n",
    "                print(\"猜这么多次都不对，你个der\")\n",
    "                print(\"正确答案是： %s\"%hide_card)\n",
    "                break\n",
    "else:\n",
    "    print(\"请输入数字在0-99之间。不要耍赖！\")\n",
    "                "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "35e1dc06",
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "product_list = [\n",
    "    (\"为p30\",4000),\n",
    "    (\"Mac pr\",16000),\n",
    "    (\"Milk tea\",20),\n",
    "    (\"crabs\",88),\n",
    "    (\"bike\",400),\n",
    "    (\"watch\",40000),\n",
    "    (\"head first python\",128),\n",
    "    (\"book\",40),\n",
    "]\n",
    "shopping_car = []\n",
    "zhifubao = input(\"请输入支付宝余额:\")\n",
    "# 购物车商品选择\n",
    "if zhifubao.isdigit():\n",
    "    zhifubao = int(zhifubao)\n",
    "    while True:\n",
    "        for item in product_list:\n",
    "            print(product_list.index(item),item)\n",
    "        choice = input(\"请选择你要购买的商品序号：\")\n",
    "        #商品的选择\n",
    "        if choice.isdigit():\n",
    "            choice = int(choice)\n",
    "            if choice >= 0 and choice < 8:\n",
    "                if zhifubao >= product_list[choice][1]:\n",
    "                    zhifubao = zhifubao - product_list[choice][1]\n",
    "                    shopping_car.append(product_list[choice])\n",
    "                    print(\"你把商品%s添加到购物车，你的支付宝余额是%s:\"%(product_list[choice][0],zhifubao))\n",
    "                else:\n",
    "                    print(\"你的支付宝余额不足，请重新选择商品\")\n",
    "            else:\n",
    "                print(\"商品列表里面没有这个商品，请重新选择一个商品\")\n",
    "        elif choice ==\"q\":\n",
    "            print(\"-----购物车清单-----\")\n",
    "            for i in shopping_car:\n",
    "                print(item)\n",
    "            print(\"支付宝余额%s:\"% zhifubao)\n",
    "            break\n",
    "        else:\n",
    "            print(\"按q退出程序\")\n",
    "else:\n",
    "    print(\"请输入数字\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "af382441",
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "EOL while scanning string literal (2854595893.py, line 26)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  Input \u001b[1;32mIn [37]\u001b[1;36m\u001b[0m\n\u001b[1;33m    print(\"您的余额不足\"+str(good_list[user_choice][1])+\"元，请更换其它支付方式或选择其它商品，欢迎下次光临)\u001b[0m\n\u001b[1;37m                                                                             ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m EOL while scanning string literal\n"
     ]
    }
   ],
   "source": [
    "# 1 运行程序后，让用户输入支付宝余额✔,然后打印我们的列表给用户✔\n",
    "good_list = [\n",
    "    [\"蜜桃四季春\",6],\n",
    "    [\"柠檬四季春\",4],\n",
    "    [\"草莓波波奶盖\",10]\n",
    "    [\"杨枝甘露\",12]\n",
    "]\n",
    "# 数据存放，列表的增加(append)\n",
    "AliPay = int(input(\"请输入余额\"))\n",
    "\n",
    "while True:\n",
    "    print(\"------蜜雪冰城列表------\")\n",
    "    for i in range(4):\n",
    "        print(i,good_list[i][0],str(good_list[i][1]+\"元\"))\n",
    "# 2 让用户输入商品编号✔，进行商品的购买✔\n",
    "user_choice = int(input(\"请输入商品编号\"))\n",
    "# 3 用户选择商品后，检查用户余额是否够✔，若够直接扣款，不够则提醒客户。\n",
    "# 3.1 用户输入商品序号(数值)\n",
    "if Alipay > good_list[user_choice][1]:\n",
    "    # 余额足够\n",
    "    Alipay = Alipay - good_list[user_choice][1] # 更新用户余额\n",
    "    print(\"购买成功，请等待制作...您的余额还有：%s元\"%(Alipay))\n",
    "    \n",
    "else:\n",
    "    # 余额不够\n",
    "    print(\"您的余额不足\"+str(good_list[user_choice][1])+\"元，请更换其它支付方式或选择其它商品，欢迎下次光临)\n",
    "# 3.2用户输入其它\n",
    "elif  user_choice == \"q\":\n",
    "          print(\"感谢您的购买，欢迎下次光临\")\n",
    "          print(\"您的购物车：\"，shopping_list)\n",
    "          print(\"您的余额还有：\"，AliPay)\n",
    "          break\n",
    "else:\n",
    "          print(\"您输入的商品不存在或者您输入的内容有误\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8ded09e7",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
